<?php

class Formulaire extends Controller {

	function Formulaire()
	{
		parent::Controller();
		$this->load->helper('url');
		$this->load->model('photomodel');
		$this->load->helper(array('form', 'url', 'security'));
		$this->load->library('session');
	}
	
	function index(){
		$data = array();
		if(!empty($_POST))
			$data['error_login'] = $this->logUser();
			
		if($this->session->userdata('authentified'))
		{
			//$data['photos'] = $this->photomodel->getPhotosFromNote('1');
			//$data['photos_directory'] = '../files/photos/'; //$config['dir_photos_min']
			$this->load->model('notemodel');
			$data['error'] = '';
			$data['options_trip'] = $this->notemodel->getTrips();
			$data['options_tag'] = $this->notemodel->getTags();
			$this->load->view('formulaire',$data);
		}
		else
		{
			$this->load->view('login',$data);
		}
	}
	
	function logUser()
	{
		$query = $this->db->get('users',1);
		$row = $query->row();
		if($row->login == $this->input->post('login', TRUE)
			&& $row->password == dohash($this->input->post('password', TRUE),'md5'))
		{
			$d = array('authentified' => 1, 'user' => $row->login);
			$this->session->set_userdata($d);
			return false;
		}
		else
			return 'Error. Please verify your login / password.';
	}
	
	function logout(){
		$array_items = array('authentified' => '', 'user' => '');
		$this->session->unset_userdata($array_items);
		$this->load->view('login');
	}
	
	function saveNote(){
		$this->load->model('notemodel');
		$data['id_note'] = $this->notemodel->insertNote();
		$this->output->set_header('Content-type:text/xml; charset=utf-8');
		$this->load->view('idNote',$data);
	}
	
	function saveTagNote(){
		$this->load->model('notemodel');
		$data['id_tag'] = $this->notemodel->saveTagNote();
		$this->output->set_header('Content-type:text/xml; charset=utf-8');
		$this->load->view('idTag',$data);
	}
	
	function editTagNote(){
		$this->load->model('notemodel');
		$this->notemodel->editTagNote();
	}
	
	function saveGeo(){
		$this->load->model('notemodel');
		$data['id_geo'] = $this->notemodel->insertGeo();
		$this->output->set_header('Content-type:text/xml; charset=utf-8');
		$this->load->view('idGeo',$data);
	}
	
	function editGeo(){
		$this->load->model('notemodel');
		$this->notemodel->editGeo();
	}
	
	function editNote(){
		$this->load->model('notemodel');
		$this->notemodel->editNote();
	}	
	
	function savePhotos(){
		$this->load->model('photomodel');
		$data['photos'] = $this->photomodel->insertPhotos();
		$this->output->set_header('Content-type:text/xml; charset=utf-8');
		//$this->load->view('idGeo',$data);
	}
	function editPhotos(){
		$this->load->model('photomodel');
		$this->notemodel->editPhotos();
	}
	
	function editGeoTagPhoto(){
		$this->load->model('photomodel');
		$this->photomodel->editGeo();
	}
	
	
	
}
	
/* End of file formulaire.php */
/* Location: ./system/application/controllers/formulaire.php */
?>
